/**
 * @(#)EntityUtil.java 1.0 2016年4月8日
 * @Copyright:  Copyright 2016 - 2016 Meyli. Co. Ltd. All Rights Reserved.
 * @Description: 
 * 
 * Modification History:
 * Date:        2016年4月8日
 * Author:      gaobo
 * Version:     V1.0.0.1
 * Description: (Initialize)
 * Reviewer:    
 * Review Date: 
 */
package com.ztmg.water.util;

import java.io.*;
import java.sql.*;
import java.util.*;

/**
 * Copyright:   Copyright 2016 - 2016 Meyli. Co. Ltd. All Rights Reserved.
 * Date:        2016年4月8日 下午1:25:06
 * Author:      gaobo
 * Version:     V1.0.0.1
 * Description: 生成mybaitisxml文件，实体，接口
 */
public class BuilderMybaitis_part
{
    
    private String pro_dir = "D:\\code\\logistics\\water\\";
    
    private String java_path = "src\\main\\java\\com\\ztmg\\water\\";
    
    private String service_dir ="service";
    private String serviceImpl_dir ="impl";
    
    private String controller_dir ="controller";
    private String vo_path = "";
    private String dto_path = "";

    private String service_path = "";
    private String serviceImpl_path = "";
    
    private String controller_path = "";
    
    private String service_package = "";
    private String serviceImpl_package = "";
    
    private String controller_package = "";
    
    private String vo_package = "";
    private String dto_package = "";
    private String bean_package="";
    
    private String mapper_package = "";

    private String  beanName = "";

    private String serviceName = null;
    private String serviceImplName = null;
    private String controllerName = null;

    private String comment_text = "";

    /**
     *  将实体类名首字母改为小写
     *
     * @param beanName
     * @return
     */
    private String processResultMapId(String beanName)
    {
        return beanName.substring(0, 1).toLowerCase() + beanName.substring(1);
    }

    /**
     *  构建类上面的注释
     *
     * @param bw
     * @param text
     * @return
     * @throws IOException
     */
    private BufferedWriter buildClassComment(BufferedWriter bw, String text)
        throws IOException
    {
        bw.newLine();
        bw.newLine();
        bw.write("/**");
        bw.newLine();
        bw.write(" * ");
        bw.newLine();
        bw.write(" * " + text);
        bw.newLine();
        bw.write(" * ");
        bw.newLine();
        bw.write(" **/");
        return bw;
    }

    /**
     *  构建方法上面的注释
     *
     * @param bw
     * @param text
     * @return
     * @throws IOException
     */
    private BufferedWriter buildMethodComment(BufferedWriter bw, String text)
        throws IOException
    {
        bw.newLine();
        bw.write("\t/**");
        bw.newLine();
        bw.write("\t * ");
        bw.newLine();
        bw.write("\t * " + text);
        bw.newLine();
        bw.write("\t * ");
        bw.newLine();
        bw.write("\t **/");
        return bw;
    }
    private BufferedWriter buidLine(BufferedWriter bw,String text) throws IOException{
        bw.write(text);
        bw.newLine();
        return bw;
    }
    public void buildDTO() throws IOException
    {

        CreateFolders(dto_path);

        File serviceFile = new File(dto_path, beanName + "DTO.java");
        BufferedWriter bw = new BufferedWriter(
                new OutputStreamWriter(new FileOutputStream(serviceFile), "utf-8"));
        bw.write("package " + dto_package + ";");
        bw.newLine();
        bw.newLine();
        bw.write("import com.ztmg.common.dto.BaseDTO;");
        bw.newLine();
        bw.write("import io.swagger.annotations.ApiModel;");
        bw.newLine();
        bw.write("import io.swagger.annotations.ApiModelProperty;");
        bw.newLine();
        bw.newLine();
        bw.write("@ApiModel");
        bw.newLine();
        bw.write("public class " + beanName+"DTO"+" extends BaseDTO {");
        bw.newLine();
        bw.newLine();
        bw.write("}");
        bw.flush();
        bw.close();

    }
    public void buildPageDTO() throws IOException
    {

        CreateFolders(dto_path);

        File serviceFile = new File(dto_path, beanName + "PageDTO.java");
        BufferedWriter bw = new BufferedWriter(
                new OutputStreamWriter(new FileOutputStream(serviceFile), "utf-8"));
        bw.write("package " + dto_package + ";");
        bw.newLine();
        bw.newLine();
        bw.write("import com.ztmg.common.dto.PageReq;");
        bw.newLine();
        bw.write("import io.swagger.annotations.ApiModel;");
        bw.newLine();
        bw.write("import io.swagger.annotations.ApiModelProperty;");
        bw.newLine();
        bw.newLine();
        bw.write("@ApiModel");
        bw.newLine();
        bw.write("public class " + beanName+"PageDTO"+" extends PageReq {");
        bw.newLine();
        bw.newLine();
        bw.write("}");
        bw.flush();
        bw.close();

    }

    public void buildVO() throws IOException
    {

        CreateFolders(vo_path);

        File serviceFile = new File(vo_path, beanName + "VO.java");
        BufferedWriter bw = new BufferedWriter(
                new OutputStreamWriter(new FileOutputStream(serviceFile), "utf-8"));
        bw.write("package " + vo_package + ";");
        bw.newLine();
        bw.newLine();
        bw.write("import io.swagger.annotations.ApiModel;");
        bw.newLine();
        bw.write("import io.swagger.annotations.ApiModelProperty;");
        bw.newLine();
        bw.newLine();
        bw.write("@ApiModel");
        bw.newLine();
        bw.write("public class " + beanName+"VO"+" {");
        bw.newLine();
        bw.newLine();
        bw.write("}");
        bw.flush();
        bw.close();

    }
    public void buildService() throws IOException
    {
        
        CreateFolders(service_path);
        
        File serviceFile = new File(service_path, serviceName + ".java");
        BufferedWriter bw = new BufferedWriter(
            new OutputStreamWriter(new FileOutputStream(serviceFile), "utf-8"));
        bw.write("package " + service_package + ";");
        bw.newLine();
        bw.newLine();
        bw.write("import " + bean_package +";");
        bw.newLine();
        bw.write("import " + vo_package + "." + beanName + "VO;");
        bw.newLine();
        bw.write("import " + dto_package + "." + beanName + "DTO;");
        bw.newLine();
        bw.write("import " + dto_package + "." + beanName + "PageDTO;");
        bw.newLine();
        bw.write("import com.ztmg.common.util.resultUtils.JsonResult;");
        bw.newLine();
        bw.write("import com.github.pagehelper.PageInfo;");
        bw.newLine();
        bw.newLine();
        bw.write("public interface " + serviceName+"{");
        bw.newLine();
        bw.newLine();
        /***定义方法 start***/
        String dtoName = beanName+"DTO";
        String voName = beanName+"VO";
        buidLine(bw,"\t\tJsonResult create("+dtoName+" dto);");
        buidLine(bw,"\t\tJsonResult update("+dtoName+" dto);");
        buidLine(bw,"\t\tJsonResult<"+voName+"> selectById(Integer id);");
        buidLine(bw,"\t\tJsonResult<"+voName+"> select("+dtoName+" dto);");
        buidLine(bw,"\t\tJsonResult<PageInfo<"+voName+">> selectPage("+beanName+"PageDTO"+" dto);");
        buidLine(bw,"\t\tJsonResult deleteById(Integer id);");
        buidLine(bw,"\t\tJsonResult delete("+dtoName+" dto);");
        buidLine(bw,"\t\tJsonResult batchDelete(List<Integer> ids);");
        /***定义方法 end ***/

        bw.write("}");
        bw.flush();
        bw.close();
        
    }
    public void buildServiceImpl() throws IOException
    {
        CreateFolders(serviceImpl_path);
        
        File serviceImplFile = new File(serviceImpl_path, serviceImplName + ".java");
        BufferedWriter bw = new BufferedWriter(
            new OutputStreamWriter(new FileOutputStream(serviceImplFile), "utf-8"));
        bw.write("package " + serviceImpl_package + ";");
        bw.newLine();
        bw.newLine();

        bw.write("import " + bean_package  + ";");
        bw.newLine();
        bw.write("import " + vo_package + "." + beanName + "VO;");
        bw.newLine();
        bw.write("import " + dto_package + "." + beanName + "DTO;");
        bw.newLine();
        bw.write("import " + dto_package + "." + beanName + "PageDTO;");
        bw.newLine();
        bw.write("import com.ztmg.common.util.resultUtils.JsonResult;");
        bw.newLine();
        bw.write("import javax.annotation.Resource;");
        bw.newLine();
        bw.write("import org.springframework.stereotype.Service;");
        bw.newLine();

        buidLine(bw,"import com.github.pagehelper.PageHelper;");
        buidLine(bw,"import com.github.pagehelper.PageInfo;");
        buidLine(bw,"import com.ztmg.common.constant.ErrorConst;");
        buidLine(bw,"import org.springframework.beans.BeanUtils;");
        buidLine(bw,"import java.util.Date;");
        buidLine(bw,"import java.util.List;");
        buidLine(bw,"import java.util.stream.Collectors;");

        bw.write("import " + service_package + "." + serviceName + ";");
        bw.newLine();
        bw.write("import " + mapper_package + ";");
        buidLine(bw,"import " + bean_package  + "Example;");

        bw.newLine();

        bw.write("@Service");
        bw.newLine();
        bw.write("public class " + serviceImplName+" implements "+serviceName+"{");
        bw.newLine();
        bw.newLine();
        bw.write("    @Resource");
        bw.newLine();
        bw.write("    private "+beanName+"Mapper "+processResultMapId(beanName)+"Mapper;");
        bw.newLine();
        String dtoName = beanName+"DTO";
        String voName = beanName+"VO";
        String mapperName = processResultMapId(beanName)+"Mapper";
        
        buidLine(bw,"    @Override");
        buidLine(bw,"    public JsonResult create("+dtoName+" dto) {");
        buidLine(bw,"        if(null != dto){");
        buidLine(bw,"            "+beanName+" bean = new "+beanName+"();");
        buidLine(bw,"            BeanUtils.copyProperties(dto,bean);");
        buidLine(bw,"            bean.setCreateTime(new Date());");
        buidLine(bw,"            //后续完善");
        buidLine(bw,"            bean.setCreater(\"\");");
        buidLine(bw,"            "+mapperName+".insert(bean);");
        buidLine(bw,"            return JsonResult.success();");
        buidLine(bw,"        }else {");
        buidLine(bw,"            return JsonResult.fail(ErrorConst.SYSTEM_PARM_ERROR,ErrorConst.SYSTEM_PARM_ERROR_MSG);");
        buidLine(bw,"        }");
        buidLine(bw,"    }");
        bw.newLine();
        buidLine(bw,"    @Override");
        buidLine(bw,"    public JsonResult update("+dtoName+" dto) {");
        buidLine(bw,"        if(null != dto && null != dto.getId()){");
        buidLine(bw,"            "+beanName+" bean = new "+beanName+"();");
        buidLine(bw,"            BeanUtils.copyProperties(dto,bean);");
        buidLine(bw,"            bean.setModifyTime(new Date());");
        buidLine(bw,"            //后续完善");
        buidLine(bw,"            bean.setModifier(\"\");");
        buidLine(bw,"            "+mapperName+".updateByPrimaryKeySelective(bean);");
        buidLine(bw,"            return JsonResult.success();");
        buidLine(bw,"        }else {");
        buidLine(bw,"            return JsonResult.fail(ErrorConst.SYSTEM_PARM_ERROR,ErrorConst.SYSTEM_PARM_ERROR_MSG);");
        buidLine(bw,"        }");
        buidLine(bw,"    }");
        bw.newLine();
        buidLine(bw,"    @Override");
        buidLine(bw,"    public JsonResult<"+voName+"> selectById(Integer id) {");
        buidLine(bw,"        if(null != id){");
        buidLine(bw,"            "+beanName+" bean = "+mapperName+".selectByPrimaryKey(id);");
        buidLine(bw,"            "+voName+" vo = new "+voName+"();");
        buidLine(bw,"            if(null != bean){");
        buidLine(bw,"                BeanUtils.copyProperties(bean,vo);");
        buidLine(bw,"            }else {");
        buidLine(bw,"                return JsonResult.fail(ErrorConst.SYSTEM_PARM_ERROR,ErrorConst.SYSTEM_PARM_ERROR_MSG);");
        buidLine(bw,"            }");
        buidLine(bw,"            return JsonResult.success(vo);");
        buidLine(bw,"        }else{");
        buidLine(bw,"            return JsonResult.fail(ErrorConst.SYSTEM_PARM_ERROR,ErrorConst.SYSTEM_PARM_ERROR_MSG);");
        buidLine(bw,"        }");
        buidLine(bw,"    }");
        bw.newLine();
        buidLine(bw,"    @Override");
        buidLine(bw,"    public JsonResult<"+voName+"> select("+dtoName+" dto) {");
        buidLine(bw,"        "+beanName+"Example example = new "+beanName+"Example();");
        buidLine(bw,"        "+beanName+"Example.Criteria criteria =  example.createCriteria();");
        buidLine(bw,"        /***");
        buidLine(bw,"        * 根据具体的业务，查询条件赋值");
        buidLine(bw,"         */");
        buidLine(bw,"        List<"+beanName+"> sysUserList = "+mapperName+".selectByExample(example);");
        buidLine(bw,"        "+voName+" vo = new "+voName+"();");
        buidLine(bw,"        if(!sysUserList.isEmpty()){");
        buidLine(bw,"            BeanUtils.copyProperties(sysUserList.get(0),vo);");
        buidLine(bw,"        }");
        buidLine(bw,"        return JsonResult.success(vo);");
        buidLine(bw,"    }");
        bw.newLine();

        buidLine(bw,"    @Override");
        buidLine(bw,"    public JsonResult<PageInfo<"+voName+">> selectPage("+beanName+"PageDTO"+" dto) {");
        buidLine(bw,"        "+beanName+"Example example = new "+beanName+"Example();");
        buidLine(bw,"        "+beanName+"Example.Criteria criteria =  example.createCriteria();");
        buidLine(bw,"        /***");
        buidLine(bw,"        * 根据具体的业务，查询条件赋值");
        buidLine(bw,"         */");
        buidLine(bw,"        PageHelper.startPage(dto.getPage(), dto.getLimit());");
        buidLine(bw,"        List<"+beanName+"> beanList = "+mapperName+".selectByExample(example);");
        buidLine(bw,"        PageInfo pageInfo = new PageInfo<>(beanList);");
        buidLine(bw,"        List<"+voName+"> respDTOS = beanList.parallelStream().map((bean) -> {");
        buidLine(bw,"            "+voName+" vo = new "+voName+"();");
        buidLine(bw,"            BeanUtils.copyProperties(bean, vo);");
        buidLine(bw,"            return vo;");
        buidLine(bw,"        }).collect(Collectors.toList());");
        buidLine(bw,"        pageInfo.setList(respDTOS);");
        buidLine(bw,"        return JsonResult.success(pageInfo);");
        buidLine(bw,"    }");
        bw.newLine();
        buidLine(bw,"    @Override");
        buidLine(bw,"    public JsonResult deleteById(Integer id) {");
        buidLine(bw,"        return JsonResult.success( "+mapperName+".deleteByPrimaryKey(id));");
        buidLine(bw,"    }");
        bw.newLine();
        buidLine(bw,"    @Override");
        buidLine(bw,"    public JsonResult delete("+dtoName+" dto) {");
        buidLine(bw,"        "+beanName+"Example example = new "+beanName+"Example();");
        buidLine(bw,"        "+beanName+"Example.Criteria criteria =  example.createCriteria();");
        buidLine(bw,"        /***");
        buidLine(bw,"        * 根据具体的业务，查询条件赋值");
        buidLine(bw,"         */");
        buidLine(bw,"        return JsonResult.success("+mapperName+".deleteByExample(example));");
        buidLine(bw,"    }");
        bw.newLine();
        buidLine(bw,"    @Override");
        buidLine(bw,"    public JsonResult batchDelete(List<Integer> ids) {");
        buidLine(bw,"        "+beanName+"Example example = new "+beanName+"Example();");
        buidLine(bw,"        "+beanName+"Example.Criteria criteria =  example.createCriteria();");
        buidLine(bw,"        criteria.andIdIn(ids);");
        buidLine(bw,"        return JsonResult.success("+mapperName+".deleteByExample(example));");
        buidLine(bw,"    }");


        bw.write("}");
        bw.flush();
        bw.close();
    }   
    public void buildController() throws IOException{

        CreateFolders(controller_path);
        
        File serviceImplFile = new File(controller_path, controllerName + ".java");
        BufferedWriter bw = new BufferedWriter(
            new OutputStreamWriter(new FileOutputStream(serviceImplFile), "utf-8"));
        bw.write("package " + controller_package + ";");
        bw.newLine();
        bw.newLine();

        bw.write("import com.ztmg.common.util.resultUtils.JsonResult;;");
        bw.newLine();
        bw.write("import io.swagger.annotations.Api;");
        bw.newLine();
        bw.write("import io.swagger.annotations.ApiOperation;");
        bw.newLine();
        bw.write("import org.springframework.web.bind.annotation.GetMapping;");
        bw.newLine();
        bw.write("import org.springframework.web.bind.annotation.PostMapping;");
        bw.newLine();
        bw.write("import org.springframework.web.bind.annotation.RequestMapping;");
        bw.newLine();
        bw.write("import org.springframework.web.bind.annotation.RestController;");
        bw.newLine();
        bw.write("import javax.annotation.Resource;");
        bw.newLine();
        bw.write("import org.springframework.web.bind.annotation.*;");
        bw.newLine();
        buidLine(bw,"import com.github.pagehelper.PageInfo;");

        bw.newLine();
        bw.newLine();
        bw.write("import " + vo_package + "." + beanName + "VO;");
        bw.newLine();
        bw.write("import " + dto_package + "." + beanName + "DTO;");
        bw.newLine();
        bw.write("import " + dto_package + "." + beanName + "PageDTO;");
        bw.newLine();
        bw.write("import " + service_package + "." +serviceName + ";");
        bw.newLine();
        bw = buildClassComment(bw, controllerName + "Controller");
        bw.newLine();
        bw.newLine();
        bw.write("@Api(description = \""+comment_text+"接口\")");
        bw.newLine();
        bw.write("@RestController");
        bw.newLine();
        bw.write("@RequestMapping(value = \"/"+processResultMapId(beanName)+"\")");
        bw.newLine();
        bw.write("public class " + controllerName+"{");
        bw.newLine();
        bw.newLine();
        bw.write("\t@Resource");
        bw.newLine();
        bw.write("\tprivate "+serviceName+" "+processResultMapId(serviceName)+";");
        bw.newLine();
        bw.newLine();
        String dtoName = beanName+"DTO";
        String voName = beanName+"VO";
        String service = processResultMapId(serviceName);
        
        buidLine(bw,"    @PostMapping(\"create\")");
        buidLine(bw,"    @ApiOperation(\"新增\")");
        buidLine(bw,"    public JsonResult create(@RequestBody "+dtoName+" dto){");
        buidLine(bw,"        return "+service+".create(dto);");
        buidLine(bw,"    }");
        bw.newLine();
        buidLine(bw,"    @PostMapping(\"update\")");
        buidLine(bw,"    @ApiOperation(\"修改\")");
        buidLine(bw,"    public JsonResult update(@RequestBody "+dtoName+" dto){");
        buidLine(bw,"        return "+service+".update(dto);");
        buidLine(bw,"    }");
        bw.newLine();
        buidLine(bw,"    @GetMapping(\"detail/{id}\")");
        buidLine(bw,"    @ApiOperation(\"详情\")");
        buidLine(bw,"    public JsonResult<"+voName+"> detail(@PathVariable Integer id){");
        buidLine(bw,"        return "+service+".selectById(id);");
        buidLine(bw,"    }");
        bw.newLine();
        buidLine(bw,"    @PostMapping(\"select\")");
        buidLine(bw,"    @ApiOperation(\"条件查询\")");
        buidLine(bw,"    public JsonResult<"+voName+"> detail(@RequestBody "+dtoName+" dto){");
        buidLine(bw,"        return "+service+".select(dto);");
        buidLine(bw,"    }");
        bw.newLine();
        buidLine(bw,"    @PostMapping(\"queryPage\")");
        buidLine(bw,"    @ApiOperation(\"分页查询\")");
        buidLine(bw,"    public JsonResult<PageInfo<"+voName+">> queryPage(@RequestBody "+beanName+"PageDTO dto){");
        buidLine(bw,"        return "+service+".selectPage(dto);");
        buidLine(bw,"    }");
        bw.newLine();
        buidLine(bw,"    @PostMapping(\"delete\")");
        buidLine(bw,"    @ApiOperation(\"条件删除\")");
        buidLine(bw,"    public JsonResult delete(@RequestBody "+dtoName+" dto){");
        buidLine(bw,"        return "+service+".delete(dto);");
        buidLine(bw,"    }");
        bw.newLine();
        buidLine(bw,"    @GetMapping(\"deleteById/{id}\")");
        buidLine(bw,"    @ApiOperation(\"删除\")");
        buidLine(bw,"    public JsonResult deleteById(@PathVariable Integer id){");
        buidLine(bw,"        return "+service+".deleteById(id);");
        buidLine(bw,"    }");
        bw.newLine();
        bw.newLine();
        buidLine(bw,"    @PostMapping(\"batchDelete\")");
        buidLine(bw,"    @ApiOperation(\"批量删除\")");
        buidLine(bw,"    public JsonResult batchDelete(@RequestBody List<Integer> ids){");
        buidLine(bw,"        return "+service+".batchDelete(ids);");
        buidLine(bw,"    }");
        bw.newLine();

        bw.write("}");
        bw.flush();
        bw.close();
    
    }
    /**
     * 
     * @param moduleName 模板名称
     * @throws ClassNotFoundException
     * @throws SQLException
     * @throws IOException
     */
    public void generate(String moduleName, String beanName)
        throws ClassNotFoundException, SQLException, IOException
    {
        this.beanName = beanName;
        initParameter(moduleName);
       // buildDTO();
       // buildPageDTO();
      //  buildVO();
        buildService();
        buildServiceImpl();
        buildController();
    }
    
    private void initParameter(String moduleName)
    {
        dto_path =  pro_dir + java_path +"dto"+ File.separator+moduleName;
        vo_path =  pro_dir + java_path +"vo"+ File.separator+moduleName;
        service_path = pro_dir + java_path +service_dir+ File.separator + moduleName;
        serviceImpl_path = service_path+ File.separator+serviceImpl_dir;
        
        service_package = "com.ztmg.water.service." + moduleName;
        serviceImpl_package = service_package+".impl";
        
        controller_path = pro_dir + java_path  + controller_dir + File.separator+ moduleName;
        controller_package = "com.ztmg.water.controller." + moduleName;

        mapper_package = "com.ztmg.water.mapper."+moduleName+"."+beanName+"Mapper";
        bean_package = "com.ztmg.water.model."+moduleName+"."+beanName;
        vo_package = "com.ztmg.water.vo."+moduleName;
        dto_package = "com.ztmg.water.dto."+moduleName;

        serviceName = beanName+"Service";
        serviceImplName=serviceName+"Impl";
        controllerName=beanName+"Controller";
        
    }
    
    public void CreateFolders(final String folders)
    {
        StringTokenizer st = new StringTokenizer(folders, File.separator);
        StringBuilder sb = new StringBuilder();
        String osname = System.getProperty("os.name");
        if (osname.compareToIgnoreCase("linux") == 0)
            sb.append(File.separator);
        
        while (st.hasMoreTokens())
        {
            sb.append(st.nextToken());
            File file = new File(sb.toString());
            if (!file.exists())
                file.mkdir();
            sb.append(File.separator);
        }
        
    }
    public static ArrayList<String> getFiles(String path) {
        ArrayList<String> files = new ArrayList<String>();
        File file = new File(path);
        File[] tempList = file.listFiles();

        for (int i = 0; i < tempList.length; i++) {
            if (tempList[i].isFile()) {
//              System.out.println("文     件：" + tempList[i]);
                String name = tempList[i].getName();
                if(name.indexOf("Example")<0){
                    System.out.println("文     件：" + name.replace(".java",""));
                    files.add(name.replace(".java",""));
                }

            }
            if (tempList[i].isDirectory()) {
//              System.out.println("文件夹：" + tempList[i]);
                files.add(tempList[i].getName());
               // String moduleName = tempList[i].getName();
               // System.out.println(moduleName);

            }
        }
        return files;
    }
    public static  Map<String,List<String>> getBean(String path){
        Map<String,List<String>> moduleMap = new HashMap<>();
        List<String> moduleList = BuilderMybaitis_part.getFiles(path);
        for (String moduleName:moduleList) {
            List<String> beanList = BuilderMybaitis_part.getFiles( path + File.separator+ moduleName);
            moduleMap.put(moduleName,beanList);
        }
        return moduleMap;
    }
    public static void main(String[] args)
    {
        Map<String,List<String>> listMap = BuilderMybaitis_part.getBean("D:\\code\\logistics\\water\\src\\main\\java\\com\\ztmg\\water\\model");
        for (String moduleName:listMap.keySet()) {
            List<String> beanNameList = listMap.get(moduleName);
            for (String beanName: beanNameList ) {
                try
                {
                    new BuilderMybaitis_part().generate(moduleName, beanName);
                    System.out.println("OK!======>>"+beanName);
                }
                catch (ClassNotFoundException e)
                {
                    e.printStackTrace();
                }
                catch (SQLException e)
                {
                    e.printStackTrace();
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }

        }
        System.out.println("OK!");
    }
}
